﻿CREATE PROCEDURE [dbo].[ListResourceByIDs]
@UserIDs NVARCHAR (512), @StartDate DATETIME, @EndDate DATETIME
AS
DECLARE @sql nvarchar(1024)
    
    SET @sql = 'SELECT U.UserID, U.UserName, '
    SET @sql = @sql + ' Sum(EL.Duration) AS totalHours'
    SET @sql = @sql + ' FROM EntryLog EL INNER JOIN Users U'
    SET @sql = @sql + ' ON EL.UserID = U.UserID '
    SET @sql = @sql + ' WHERE U.UserID IN (' + @UserIDs + ') '
    SET @sql = @sql + ' AND EL.EntryDate >= ' +CAST(@StartDate as nvarchar(20))+ ' AND EL.EntryDate <= ' + CAST(@EndDate as nvarchar(20))	
    SET @sql = @sql + ' GROUP BY U.UserID, U.UserName'

    EXEC sp_executesql @sql

